// /rule/addRuleInfo.do
document.write('<script type="text/javascript" src="../static/js/back/utils.js"></script>');
document.write('<script type="text/javascript" src="../static/js/back/ajax.js"></script>');
var _url_ = '';
var _url_edit = '../order/updateOrderCommentList.do';
var _url_list = '../order/getOrderCommentList';
var _url_id = '';
var _map = {};
///首页
var _pageNum = 1;
var _type ;
var spid="";
  $(function(){
	   
	   spid = getCookie("shop_id");
	  _type = getUrlParam("type");
	  console.log(_type);
	  if(_type === "add"){
		  getTypeListAdd();
		  $("#shopId").val(spid);
	  }else if(_type === "edit"){
		  _url_ = _url_edit;
	  }else{
//		  getTypeList();
//		  getProfitsInfo();
		  getList();
	  }
  })
$(function(){
	  $("body").on("click",".mypage span",function(){
		  _pageNum = $(this).attr("data-status");
		  getList();
	  })
	  $(".search-btn").click(function(){
			 var start =  $("#startTime").val();
			 var end =  $("#endTime").val();
			 _map["startTime"] = start;
			  if(end){
				  end =  addDate(end,1);
			  }
			  _pageNum = 1;
			 _map["endTime"] = end;
			 getList();
		  });
	  $("body").on("click",".left-type li",function(){
			 var tt = $(this).text();
			 $(this).addClass('lt-li-active').siblings().removeClass('lt-li-active');
			 _map['goodsTypeId'] = $(this).attr('data-status');
			 getList();
	  });
});
  function getList(){
	  _map['shopId'] = spid;
	  _map['pageNum'] = _pageNum;
	  _ajax_get(_url_list,_map,function(res){
		  console.log(res);
		  console.log(res.returnObject);
		  if(!res.returnObject||res.returnObject.length<=0 ){
			  $(".layui-table tbody").html("");
			  $(".no-more-data").show();
			  $(".mypage").hide();
			  return;
		  }else{
			  $(".mypage").show();
			  $(".no-more-data").hide();
		  }
		  var html = "";
		  var stat = "" , statHtml = "";
		  showPageInfo(res.returnObject);
		  $(".x-right").text("共有数据："+res.returnObject.total +" 条");
		  var html,stat,statStr,payTypeStr,sendTypeStr;
		  $.each(res.returnObject.list,function(i,v,arr){
			  var tit ="" , orderInfo = "";
			  var orlist  = v.list;
			  for (var k = 0; k < orlist.length; k++) {
				  tit += orlist[k].goodsTitle +'&nbsp;&nbsp;&nbsp;x'+orlist[k].goodsNum +'\n';
				  if(k<=1 ){
					  orderInfo = tit;
				  }else{
					  orderInfo +='...';
				  }
			  }
			  var ppp = v.commentPic.split(',');
			  var piccom = '';
			  for (var i = 0; i < ppp.length; i++) {
				  console.log(ppp[i]);
				  if(ppp[i] && ppp[i] != 'null'){
					  piccom += '<img height=50 widht=50 style="padding:5px;" onclick="clickToBigImg(this)" src = "' +ppp[i] + '" />';
				  }
				  
			  }
			  console.log(v);
			  html+=' <tr><td>'
// 	             +' <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="'+v.id+'" ><i class="layui-icon">&#xe605;</i></div>'
// 	             +' </td>                                                                                                                  '
// 	             +' <td>'
 	             +(i+1)+'</td>                                                                                                             '
 	             +' <td>'+v.userNickName
 	             +'</td>                                                                                           '
// 	             +' <td align="center"><a target="_blank" href="'+v.adUrl+'"><img  src="'+v.adPic+'" height=50 widht=50 ></a></td>                                                                                                      '
// 	             +' <td>'+v.adUrl+'</td>                                                                                                      '
 	             +' <td>'+v.commentStar+'</td>                                                                                                      '
 	             +' <td title="'+v.content+'">'+v.content+'</td>                                         '
 	             +' <td >'+piccom+'</td>                                         '
 	             +' <td title="'+tit+'">'+orderInfo+'</td>                                                                                                      '
 	             +' <td>'+v.modifyTime+'</td>                                                                                                      '
 	             +' <td class="td-manage">    '
 	             + '<a title="删除" onclick="member_del(this,\''+v.id+'\')" href="javascript:;">                                         '
 	             +'     <i class="iconfont icon-delete x-red"></i>                                                                                 '
 	             +'   </a>  </td> </tr>';
		  })
		  $(".layui-table tbody").html(html);
	  })
  }
  
  function getListByStat(stat){
	  if(stat){
		  _map['starStr'] = stat;
	  }else{
		  _map['starStr'] = '';
	  }
	  getList();
  }
  function getListByHasCon(stat){
	  if(stat){
		  _map['hasCon'] = stat;
	  }else{
		  _map['hasCon'] = '';
	  }
	  getList();
  }
  /*用户-删除*/
  function member_del(obj,_id){
      layer.confirm('确认要删除吗？',function(index){
          //发异步删除数据
    	  _ajax_post_token(_url_edit,{status:0,id:_id},function(res){
    	      	console.log(res);
    	      	if(res.resultCode == 1000){
    	      		getList();
    	      	  layer.msg('删除成功!',{icon:6,time:2000});
    	      	}else{
    	      		layer.msg('删除失败!',{icon:5,time:2000});
    	      	}
    	      });
      });
  }
      
  function updateInfo(data){
	  //发异步，把数据提交给后台
	 console.log(_url_);
	 data['shopId'] = spid;
      _ajax_post_token(_url_,data,function(res){
      	console.log(res);
      	if(res.resultCode == 1000){
      	  parent.getList();
      	  parent.layer.msg('操作成功!',{icon:1,time:2000});
      	  x_admin_close();
          // 获得frame索引
      	}else{
      		layer.msg('操作失败!',{icon:1,time:2000});
      	}
      });
  }
  function clickToBigImg(obj){//绑定图片函数
      //var clickImgId = $(this).attr("id");
      var imgsrc = $(obj).attr("src");
      //alert (imgsrc);
      console.log(imgsrc);
      var opacityBottom = '<div title="点击图片关闭预览" id="opacityBottom" style="display: none"><img class="bigImg" src="'+ imgsrc +'" ></div>';
      $(document.body).append(opacityBottom);
      toBigImg();//变大函数
  }
  
	function toBigImg() {

		$("#opacityBottom").addClass("opacityBottom");
		$("#opacityBottom").show();
		$("html,body").addClass("none-scroll");//下层不可滑动
		$(".bigImg").addClass("bigImg");
		/*隐藏*/
		$("#opacityBottom").bind("click", clickToSmallImg);
		$(".bigImg").bind("click", clickToSmallImg);
		var imgHeight = $(".bigImg").prop("height");
		if (imgHeight < h) {
			$(".bigImg").css({
				"top" : (h - imgHeight) / 2 + 'px'
			});

		} else {
			$(".bigImg").css({
				"top" : '0px'
			});
		}
		function clickToSmallImg() {
			$("html,body").removeClass("none-scroll");
			$("#opacityBottom").remove();
		}
	};    
 
      
//添加 和 修改窗口     